<template>
  <div>
<h2>房型修改</h2>
  </div>
  <table border="1">
    <tr>
      <td>房号</td>
      <td>
        <input type="number" v-model="state.roomNumber" >
      </td>
    </tr>
    <tr>
      <td>房型名称</td>
      <td>
        <input type="text" v-model="state.roomName" >
      </td>
    </tr>
    <tr>
      <td>房间数量</td>
      <td>
        <input type="text" v-model="state.roomNum">
      </td>
    </tr>
    <tr>
      <td>门市价</td>
      <td>
        <input type="text" v-model="state.roomPrice">
      </td>
    </tr>
    <tr>
      <td></td>
      <td>
        <input type="button" value="修改" @click="add">
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import{reactive,toRefs,onMounted}from'vue'
import { useRoute,useRouter } from 'vue-router';
let router=useRouter();
let route=useRoute();
let data:any=reactive({
  state:{
  roomNumber: '',
  roomName: '',
  roomNum: '',
  roomPrice: ''
  }
})
let {state}=toRefs(data)
function add()
{
  let obj={
  "id":route.query.id,
  "roomNumber": state.value.roomNumber,
  "roomName": state.value.roomName,
  "roomNum": state.value.roomNum,
  "roomPrice": state.value.roomPrice
  }
  axios({
    url:'/api/RoomType/Upda',
    method:'post',
    data:obj
  })
  .then(res=>{
if(res.data.data==1)
{
  alert("修改成功")
  router.push("../show")
}
  })
  .catch(err=>{
  })
}
onMounted(()=>{
  FanTian()
})
const FanTian=()=>{
  console.log(route.query.id)
  let obj={
    id:route.query.id
  }
  axios({
    url:'/api/RoomType/Fantian',
    method:'get',
    params:'obj'
  })
  .then(res=>{
    state.value=res.data.data
  })
  .catch(err=>{
  })
}
</script>

<style scoped>

</style>